﻿/*********************************************************************
 * @file       main.cpp
 * @brief      Qt启动函数main
 * @details    程序主体从这里拉起
 * @author     南樟(a2169272059@163.com)
 * @date       2025-2-10
 * @version    1.0.0
 * @copyright  a2169272059@163.com
 *********************************************************************/
#include "mainwindow.h"
#include <QStyleFactory>
#include <QPalette>
#include <QApplication>
#include <QMessageBox>

#include "sqlite.h"
#include "ticktimer.h"
///主滴答触发器
tickTimer *g_ticker;
/**
 * @brief qMain Qt启动函数main
 * @param argc 程序启动的参数char长度
 * @param argv 储存程序启动时的参数
 * @return 程序主循环体
 *  @retval -1 程序启动失败
 */
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    // 设置主题
    // "Windows", "Fusion", "Macintosh"
    a.setStyle(QStyleFactory::create("Fusion"));

    // 创建并应用浅色调色板
    QPalette Palette = a.palette();
    Palette.setColor(QPalette::Window, Qt::white);
    Palette.setColor(QPalette::WindowText, Qt::black);
    Palette.setColor(QPalette::Base, Qt::lightGray);
    Palette.setColor(QPalette::AlternateBase, Qt::white);
    Palette.setColor(QPalette::Text, Qt::black);
    Palette.setColor(QPalette::Button, Qt::white);
    Palette.setColor(QPalette::ButtonText, Qt::black);
    // Palette.setColor(QPalette::);

    a.setPalette(Palette);

    if(!db.openDatabase("betaTest.db")){
        return -1;
    }
    if(!db.createTable_clock()||!db.createTable_clock_break()
        ||!db.createTable_day_duration()||!db.createTable_task()
        ||!db.createTable_week_duration()
        ){
        return -1;
    }
    MainWindow w;
    g_ticker = new tickTimer(&w);
    if(!db.createTable_clock()||!g_ticker->load_clock()){
        QMessageBox::warning(&w,"警告","闹钟数据读取失败，\n这可能意味着闹钟工具失效");
        qDebug()<<"定时器取消";
    }else{
        g_ticker->start();
    }
    w.show();
    return a.exec();
}
